package com.hzlx.records.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.records.domain.OperationRecords;
import com.hzlx.records.service.IOperationRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工序执行记录Controller
 * 
 * @author dk
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/production")
public class OperationRecordsController extends BaseController
{
    @Autowired
    private IOperationRecordsService operationRecordsService;

    /**
     * 查询工序执行记录列表
     */
    @GetMapping("/records/list")
    public TableDataInfo list(OperationRecords operationRecords)
    {
        startPage();
        List<OperationRecords> list = operationRecordsService.selectOperationRecordsList(operationRecords);
        return getDataTable(list);
    }

    /**
     * 导出工序执行记录列表
     */
    @RequiresPermissions("production-service:records:export")
    @Log(title = "工序执行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/records/export")
    public void export(HttpServletResponse response, OperationRecords operationRecords)
    {
        List<OperationRecords> list = operationRecordsService.selectOperationRecordsList(operationRecords);
        ExcelUtil<OperationRecords> util = new ExcelUtil<OperationRecords>(OperationRecords.class);
        util.exportExcel(response, list, "工序执行记录数据");
    }

    /**
     * 获取工序执行记录详细信息
     */
    @RequiresPermissions("production-service:records:query")
    @GetMapping(value = "/records/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(operationRecordsService.selectOperationRecordsByRecordId(recordId));
    }

    /**
     * 新增工序执行记录
     */
    @RequiresPermissions("production-service:records:add")
    @Log(title = "工序执行记录", businessType = BusinessType.INSERT)
    @PostMapping("/records")
    public AjaxResult add(@RequestBody OperationRecords operationRecords)
    {
        return toAjax(operationRecordsService.insertOperationRecords(operationRecords));
    }

    /**
     * 修改工序执行记录
     */
    @RequiresPermissions("production-service:records:edit")
    @Log(title = "工序执行记录", businessType = BusinessType.UPDATE)
    @PutMapping("/records")
    public AjaxResult edit(@RequestBody OperationRecords operationRecords)
    {
        return toAjax(operationRecordsService.updateOperationRecords(operationRecords));
    }

    /**
     * 删除工序执行记录
     */
    @RequiresPermissions("production-service:records:remove")
    @Log(title = "工序执行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/records/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(operationRecordsService.deleteOperationRecordsByRecordIds(recordIds));
    }
}
